{{- /*
Including file contents in article. If no syntax highlighting language is specified,
the syntax highlighting language from the file extension will be automatically selected.

@param {string} (positional parameter 0) File path.
@param {string} (positional parameter 1) Syntax highlighting. If not specified, the syntax is determined by the file extension.

@returns {template.HTML}

@examples

  {{< file "README.md" "md" >}}
*/ -}}

{{- if (.Get 0) -}}

    {{ $file := (.Get 0) }}
    {{ $lang := (.Get 1) }}

    {{ with ($.Page.Resources.Match ($file)) }}
        {{ range . }}
            {{ $cp := ((printf "clipboard-%s-%s" ($.Name) (delimit (shuffle (seq 11 99)) "")) | md5) }}
            <div class="shortcode shortcode-{{ ($.Name) }} mb-3">
              <div class="card overflow-hidden" data-bs-theme="dark">
                <div class="card-header">
                  <div class="d-flex align-items-center">
                    <div class="flex-shrink-0">
                      <i class="far fa-file-code fa-fw"></i>
                    </div>
                    <div class="flex-grow-1 mx-2 text-truncate">
                      <code>{{ (.Name) }}</code>
                    </div>
                    <div class="flex-shrink-0">
                      <ul class="list-inline mb-0">
                        <li class="list-inline-item" data-bs-tooltip data-bs-title='{{ (i18n "sc.file.copy") }}'>
                          <a class="text-body" href="#"
                             data-fn="clipboard" data-clipboard-target="#cp-{{ ($cp) }}"
                             role="button" aria-label='{{ (i18n "sc.file.copy") }}'>
                            <i class="fas fa-copy fa-fw"></i>
                          </a>
                        </li>
                        <li class="list-inline-item" data-bs-tooltip data-bs-title='{{ (i18n "sc.file.download") }}'>
                          <a class="text-body" href="{{ (.RelPermalink) }}" download
                             role="button" aria-label='{{ (i18n "sc.file.download") }}'>
                            <i class="fas fa-download fa-fw"></i>
                          </a>
                        </li>
                        <li class="list-inline-item" data-bs-tooltip data-bs-title='{{ (i18n "sc.file.link") }}'>
                          <a class="text-body" href="{{ (.RelPermalink) }}" target="_blank"
                             role="button" aria-label='{{ (i18n "sc.file.link") }}'>
                            <i class="fas fa-arrow-up-right-from-square fa-fw"></i>
                          </a>
                        </li>
                      </ul>
                    </div>
                  </div>
                </div>
                <div class="card-body p-0 overflow-auto" id="cp-{{ ($cp) }}">
                    {{ if (eq (($lang) | len) 0) }}
                        {{ $lang = ((replace (path.Ext (.Name)) "." "") | default "plaintext") }}
                    {{ end }}
                    {{ (highlight ((.Content) | chomp) ($lang)) }}
                </div>
              </div>
            </div>
        {{ end }}
    {{ end }}

{{- else -}}

    {{ (partial "alerts/no_params" .) }}

{{- end -}}
